define([ "app", "jquery", "md5", "ecb","artDialog","iframeTools",  "services/UserService","services/TipsService",
		"directives/AudioPlayer",
		"resources/company/CompanyResource",
		"resources/UserResource", "resources/ShareResource" ],
		function(app) {
			var deps = [ "$scope", "$state","$sce", "$timeout", "$window", "$location", "$stateParams","TipsService", "UserService", "UserResource", "ShareResource","CompanyResource" ];

			function controller($scope, $state,$sce,$timeout, $window, $location, $stateParams,TipsService, UserService, UserResource, ShareResource,CompanyResource) {
				
				// 通过go传递参数-主键ID 
				$scope.keyId=$stateParams.keyId;
				queryData();
				
				$scope.choosePost =function (type){
					if(type==1){
						var parentId =$scope.positionVo.positionType1;
						CompanyResource.queryPostIno(2,parentId).success(function(data){
							$scope.postList2=data.obj;
			            });
					}else{
						var parentId =$scope.positionVo.positionType2;
						CompanyResource.queryPostIno(3,parentId).success(function(data){
							$scope.postList3=data.obj;
			            });
					}
					
				}
				
				function queryData(){
					CompanyResource.editPosition($scope.keyId).success(function(data1){
						$scope.positionVo =data1.obj
						
						// 第一级
						CompanyResource.queryPostIno(1,null).success(function(data){
							$scope.postList1=data.obj;
							$scope.positionVo.positionType1=data1.obj.positionType1;
			            });
						
						//  第二级
						CompanyResource.queryPostIno(2,data1.obj.positionType1).success(function(data){
							$scope.postList2=data.obj;
							$scope.positionVo.positionType2=data1.obj.positionType2;
			            });
						
						CompanyResource.queryPostIno(3,data1.obj.positionType2).success(function(data){
							$scope.postList3=data.obj;
							$scope.positionVo.positionType3=data1.obj.positionType3;
			            });
						
						
						if($scope.positionVo.workNature==1){
							$("#id1").addClass("position_leida_select");
							$("#id3").removeClass("position_leida_select");
							$("#id2").removeClass("position_leida_select")
							$("#id2").addClass("position_leida");
							$("#id3").addClass("position_leida");
						}
						if($scope.positionVo.workNature==2){
							$("#id2").addClass("position_leida_select");
							$("#id1").addClass("position_leida");
							$("#id3").addClass("position_leida");
							$("#id3").removeClass("position_leida_select");
							$("#id1").removeClass("position_leida_select")
						}
						
						if($scope.positionVo.workNature==3){
							$("#id3").addClass("position_leida_select");
							$("#id1").addClass("position_leida");
							$("#id2").addClass("position_leida");
							$("#id1").removeClass("position_leida_select");
							$("#id2").removeClass("position_leida_select")
						}
		            });
				}
				// 修改职位
				$scope.updatePosition= function(){
					var obj ={};
					obj=$scope.positionVo;
					obj.workNature=$("#workNature").val();
					CompanyResource.updatePosition(obj).success(function(data){
						$state.go('home.recruitManagement');
		            });
		        };
		        // 发布职位
				$scope.changeColor= function(type){
					
					$("#workNature").val(type);
					if(type==1){
						$("#id1").addClass("position_leida_select");
						$("#id3").removeClass("position_leida_select");
						$("#id2").removeClass("position_leida_select")
						$("#id2").addClass("position_leida");
						$("#id3").addClass("position_leida");
					}
					
					if(type==2){
						$("#id2").addClass("position_leida_select");
						$("#id1").addClass("position_leida");
						$("#id3").addClass("position_leida");
						$("#id3").removeClass("position_leida_select");
						$("#id1").removeClass("position_leida_select")
					}
					
					if(type==3){
						$("#id3").addClass("position_leida_select");
						$("#id1").addClass("position_leida");
						$("#id2").addClass("position_leida");
						$("#id1").removeClass("position_leida_select");
						$("#id2").removeClass("position_leida_select")
					}
		        };
		        
			}
			controller.$inject = deps;
			return app.lazy.controller("EditRecruitManagementController", controller);
		});
